package pl.edu.agh.mwo.ui.chart;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;
import org.jfree.util.Rotation;

import pl.edu.agh.mwo.model.MenadzerPracownikow;

public class SampleChartsFactory {

	
	public static JFreeChart createPieChart(MenadzerPracownikow pracownik, int index) {
		JFreeChart chart = ChartFactory.createPieChart3D(
				"Zadaniowy czas pracy",
				createDatasetforPieChart(pracownik, index), true, true, false);

		PiePlot3D plot = (PiePlot3D) chart.getPlot();
		plot.setStartAngle(290);
		plot.setDirection(Rotation.CLOCKWISE);
		plot.setForegroundAlpha(0.5f);
		return chart;
	}

	private static PieDataset createDatasetforPieChart(MenadzerPracownikow pracownik, int index) {
		DefaultPieDataset result = new DefaultPieDataset();
		
		if (index != -1 && index < pracownik.getListaPracownikow().size()) {
			String imie = pracownik.getListaPracownikow().get(index).getImie();
			String nazwisko = pracownik.getListaPracownikow().get(index).getNazwisko();
			
			int liczba_projektow = pracownik.getListaPracownikow().get(index).getListaProjektow().size();
			
			for (int i = 0; i < liczba_projektow; i++  ) {
				result.setValue(pracownik.getListaPracownikow().get(index).getListaProjektow().get(i).getNazwaProjektu(), pracownik.getListaPracownikow().get(index).getListaProjektow().get(i).getLiczbaGodzin());
			}
			
			
			//result.setValue("Projekt 1", 29);
			//result.setValue("Projekt 2", 20);
			//result.setValue("Projekt 3", 25);
			//result.setValue("Projekt 4", 25);	
		}
		
		return result;
	}

	public static JFreeChart createBarChart() {
		 // create the chart...
        final JFreeChart chart = ChartFactory.createBarChart(
            "Bar Chart Demo",         // chart title
            "Category",               // domain axis label
            "Value",                  // range axis label
            createDatasetforBarChart(), // data
            PlotOrientation.VERTICAL, // orientation
            true,                     // include legend
            true,                     
            false                     
        );

        return chart;	
	
	}
	
	 /**
     * Returns a sample dataset.
     * 
     * @return The dataset.
     */
    private static CategoryDataset createDatasetforBarChart() {
        
        // row keys...
        final String series1 = "First";
        final String series2 = "Second";
        final String series3 = "Third";

        // column keys...
        final String category1 = "Category 1";
        final String category2 = "Category 2";
        final String category3 = "Category 3";
        final String category4 = "Category 4";
        final String category5 = "Category 5";

        // create the dataset...
        final DefaultCategoryDataset dataset = new DefaultCategoryDataset();

        dataset.addValue(1.0, series1, category1);
        dataset.addValue(4.0, series1, category2);
        dataset.addValue(3.0, series1, category3);
        dataset.addValue(5.0, series1, category4);
        dataset.addValue(5.0, series1, category5);

        dataset.addValue(5.0, series2, category1);
        dataset.addValue(7.0, series2, category2);
        dataset.addValue(6.0, series2, category3);
        dataset.addValue(8.0, series2, category4);
        dataset.addValue(4.0, series2, category5);

        dataset.addValue(4.0, series3, category1);
        dataset.addValue(3.0, series3, category2);
        dataset.addValue(2.0, series3, category3);
        dataset.addValue(3.0, series3, category4);
        dataset.addValue(6.0, series3, category5);
        
        return dataset;
        
    }
    
   
}
